﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using SES.CMS.BL;
using SES.CMS.DO;

namespace SES.CMS
{
    public partial class Register : System.Web.UI.Page
    {
        ClientLoginBL clBL = new ClientLoginBL();
        ClientLoginDO clDO = new ClientLoginDO();
        protected void Page_Load(object sender, EventArgs e)
        {
            txtClientName.Focus();
            Page.Title = "Đăng ký thành viên";
            //txtDK.Text = new sysConfigBL().Select(new sysConfigDO { ConfigID = 9 }).ConfigValue;
        }

        protected void btnXacNhan_Click(object sender, EventArgs e)
        {
            if (1==1)
            {
                ccJoin.ValidateCaptcha(txtbv.Text);
                if (!ccJoin.UserValidated)
                {
                    Response.Write("<script language='javascript'>alert('Mã bảo vệ chưa chính xác..!!..')</script>");
                    return;
                }
                else
                {
                    if (new ClientLoginBL().CheckUser(txtUsername.Text).ClientLoginID > 0)
                    {
                        Ultility.Alert("Đã tồn tại tên đăng nhập");
                        return;
                    }
                    else
                    {
                        if (new ClientLoginBL().CheckEmail(txtEmail.Text).ClientLoginID > 0)
                        {
                            Ultility.Alert("Đã tồn tại tên Email");
                            return;
                        }
                        else
                        {
                            clDO.ClientName = txtClientName.Text;
                            clDO.Username = txtUsername.Text;
                            clDO.Password = Ultility.EncryptMd5(txtRePassword.Text);
                            clDO.Mobile = txtMobile.Text;
                            clDO.Phone = txtPhone.Text;
                            clDO.Email = txtEmail.Text;
                            clDO.Address = txtAddress.Text;
                            clDO.DetailInfo = "";

                            if (clBL.Insert(clDO) > 0)
                                Ultility.Alert("Bạn đã đăng ký thành công", "/Default.aspx");
                        }
                    }
                }
            }
        }
        protected void ResetForm()
        {
            txtClientName.Text = "";
            txtUsername.Text = "";
            txtRePassword.Text = "";
            txtPassword.Text = "";
            txtMobile.Text = "";
            txtPhone.Text = "";
            txtEmail.Text = "";
            txtAddress.Text = "";
            txtClientName.Focus();
        }

        protected void txtRePassword_TextChanged(object sender, EventArgs e)
        {
            txtRePassword.Attributes.Add("ValidationGroup", "ab");
        }
    }
}
